<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<button type="button" onclick="GetCurrentDateTime();">获取当前日期和时间</button>   
		<br/>
		<button type="button" onclick="GetWisdom();">随机一句名言</button>  
		<br/>
		<button type="button" onclick="GetPoetryauthorsList();">获取诗词作者列表</button>
		<br/>
		<button type="button" onclick="GetPoetryList();">获取诗词列表</button>
		<br/>
		<button type="button" onclick="PostNeteaseNews();">获取网易新闻</button>
		<br/>
		<!-- <button type="button" onclick="PostDeveloperlogin();">开发者登陆</button> -->
		<h2>结果输出框</h2>
		<textarea cols="200" rows="200" id="resultid"></textarea>
	</body>
	<script type="text/javascript">
		var resultid = document.getElementById('resultid');
		function GetCurrentDateTime(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/getTime');
			ajax.send();
			ajax.onreadystatechange = function(){
				if (ajax.status == 200 && ajax.readyState == 4) {
					var obj = JSON.parse(ajax.responseText)
					console.log(obj.result)
					resultid.innerText = 'result:{'+ "时间:" +obj.result.dateTime + ' ' + obj.result.weekday +'}'
				}
			}
		}
		
		function GetWisdom(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/sentences');
			ajax.send();
			ajax.onreadystatechange = function(){
				if (ajax.status == 200 && ajax.readyState == 4) {
					var obj = JSON.parse(ajax.responseText)
					console.log(obj.result)
					resultid.innerText = 'result:{' + obj.result.name + '—————— ' + obj.result.from +'}'
				}
			}
		}

				
		
		function GetPoetryauthorsList(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/poetryAuthor?count=2&page=1');
			ajax.send();
			ajax.onreadystatechange = function(){
				if (ajax.status == 200 && ajax.readyState == 4) {
					var obj = JSON.parse(ajax.responseText)
					var temp = '';
					for(var i=0;i<obj.result.length;i++){
						temp =  obj.result[i].name + ' ' +obj.result[i].simpleIntro;
					}
					console.log(obj.result)
					resultid.innerText ='result:{' + temp + '}'
				}
			}
		}
		
		function GetPoetryList(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/poetry?count=2&page=1');
			ajax.send();
			ajax.onreadystatechange = function(){
				if (ajax.status == 200 && ajax.readyState == 4) {
					var obj = JSON.parse(ajax.responseText)
					var temp = '';
					for(var i=0;i<obj.result.length;i++){
						temp =  obj.result[i].title + ' ' +obj.result[i].content;
					}
					console.log(obj.result)
					resultid.innerText ='result:{' + temp + '}'
				}
			}
		}
		
		function PostNeteaseNews(){
			var ajax = new XMLHttpRequest();
			ajax.open('POST','https://api.apiopen.top/getWangYiNews');
			ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded')
			ajax.send('page=1 & count=5');
			ajax.onreadystatechange = function(){
				if (ajax.status == 200 && ajax.readyState == 4) {
					var obj = JSON.parse(ajax.responseText)
					var temp = '';
					for(var i=0;i<obj.result.length;i++){
						temp = obj.result[i].path + ' ' + obj.result[i].image + ' ' + obj.result[i].title + ' ' +obj.result[i].passtime;
					}
					console.log(ajax.responseText)
					resultid.innerText ='result:{' + temp + '}'
				}
			}
		}
		
		
		// function PostDeveloperlogin(){
		// 	var ajax = new XMLHttpRequest();
		// 	ajax.open('POST','https://api.apiopen.top/developerLogin');
		// 	ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded')
		// 	ajax.send('name= peakchao & passwd = 123456');
		// 	ajax.onreadystatechange = function(){
		// 		if (ajax.status == 200 && ajax.readyState == 4) {
		// 			var obj = JSON.parse(ajax.responseText)
		// 			var temp = '';
		// 			for(var i=0;i<obj.result.length;i++){
		// 				temp = obj.result[i].apikey;
		// 			}
		// 			console.log(ajax.responseText)
		// 			resultid.innerText ='result:{' + temp + '}'
		// 		}
		// 	}
		// }
		onload = function(){
			// GET
			GetCurrentDateTime();
			GetWisdom();
			GetPoetryauthorsList();
			GetPoetryList();
			// POST
			PostNeteaseNews();
			PostTencentNewsInterface();
			// PostDeveloperlogin();
		}
	</script>
</html>
